import org.apache.ibatis.entity.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @description:
 * @author: <a href='mailto:maruichao52@gmail.com'>MRC</a>
 * @since 2022/3/3
 **/
public class Main {

    public static void main(String[] args) throws IOException {

        // 通过类加载器获得文件输入流
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");

        // 将文件输入流解析为SqlSession
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession sqlSession = sqlSessionFactory.openSession();

        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

        List<User> list = userMapper.selectAll();

        System.out.println(list.getClass().toString());
        System.out.println(list.toString());

        int num = userMapper.update();
        System.out.println("修改数量=" + num);

        sqlSession.close();
        inputStream.close();
    }

}
